﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using Argos.Scheduling;
using Argos.Windows.Forms;

namespace Argos.Design
{
	public class WeekdayListTypeEditor : UITypeEditor
	{

		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			using (WeekdaySelectorDialog dlg = new WeekdaySelectorDialog())
			{
				WeekdayList list = value as WeekdayList;
				if (null == list)
				{
					list = new WeekdayList();
				}
				dlg.SelectedDays.AddRange(list);
				if (dlg.ShowDialog() == DialogResult.OK)
				{
					list.Clear();
					list.AddRange(dlg.SelectedDays);
					return list;
				}
			}

			return value;
		}

		public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

	}
}
